import os
import wx
import requests
from io import BytesIO

class ImageLoader:
    @staticmethod
    def load_image(image_path_or_url):
        """加载图片，支持本地路径和远程URL"""
        if image_path_or_url.startswith('http'):
            # 加载远程图片
            response = requests.get(image_path_or_url)
            if response.status_code == 200:
                image_data = BytesIO(response.content)
                return wx.Image(image_data, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
            else:
                raise Exception(f"Failed to load image from URL: {image_path_or_url}")
        else:
            # 加载本地图片
            if not os.path.exists(image_path_or_url):
                raise FileNotFoundError(f"Image not found: {image_path_or_url}")
            return wx.Image(image_path_or_url, wx.BITMAP_TYPE_ANY).ConvertToBitmap()